SQL集約関数(Aggregate Function)
基本的なものは https://sqlite.org/lang_aggfunc.html を見るとわかりやすい
https://www.postgresql.jp/document/10/html/functions-aggregate.html PostgreSQLにはもっと色々ある(統計的なものや順序集合集約関数を含む)
SQLite3に定義されているもの
count(*), count(X)
sum(X) total(X)
max(X) min(X)
avg(X)
group_concat(X), group_concat(X, Y)
テクニック
ユニークなものをカウントするとき→ count(distinct(column_name))
これに限らず集合関数の引数にはdistinctをつけることができる
FILTER 句
SELECT SUM(X) FILTER (WHERE X > 10)
集約関数の値に基づくフィルタリング とは違う。
#SQL
似て非なるもの→ #window関数(windowning_function)